const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

const filterFormatAmt = (input)=>{
  let afterStr = "";
  if (input) {
    if (String(Number(input)).indexOf('.') == -1) {
      afterStr = Number(input);
    } else {
      afterStr = Number(input).toFixed(2);
    }
  } else {
    afterStr = '';
  }
  return afterStr;
}

const formatDate = (startTime)=>{
  //当前时间与2017-04-04的时间差
  // let startTime = "20171225093900";
  let formatDateStr = startTime.substring(0, 4) + "/" + startTime.substring(4, 6) + "/" + startTime.substring(6, 8) + " " + startTime.substring(8, 10) + ":" + startTime.substring(10, 12) + ":" + startTime.substring(12, 14);
  let startDate = new Date(formatDateStr);
  let endDate = new Date();
  let diff = endDate.getTime() - startDate.getTime();//时间差的毫秒数  

  //计算出相差天数  
  let days = Math.floor(diff / (24 * 3600 * 1000));

  //计算出小时数  
  let leave1 = diff % (24 * 3600 * 1000);    //计算天数后剩余的毫秒数  
  let hours = Math.floor(leave1 / (3600 * 1000));
  //计算相差分钟数  
  let leave2 = leave1 % (3600 * 1000);        //计算小时数后剩余的毫秒数  
  let minutes = Math.floor(leave2 / (60 * 1000));

  //计算相差秒数  
  let leave3 = leave2 % (60 * 1000);      //计算分钟数后剩余的毫秒数  
  let seconds = Math.round(leave3 / 1000);
  let returnStr = "刚刚";
  if (minutes > 0) {
    returnStr = minutes + "分钟前";
  }
  if (hours > 0) {
    returnStr = hours + "小时前";
  }
  if (days > 0) {
    if (days == 1) {
      returnStr = "昨天";
    } else if (days == 2) {
      returnStr = "前天";
    } else {
      returnStr = startTime.substring(0, 4) + "-" + startTime.substring(4, 6) + "-" + startTime.substring(6, 8);
    }
  }
  return returnStr;
}

const sortByTime = (tempList)=> {
  var map = {},dest = [];
  for (var i = 0; i < tempList.length; i++) {
    var ai = tempList[i];
    if (!map[ai.time.substring(0, 8)]) {
      dest.push({
        initial: ai.time,
        busInfoList: [ai]
      });
      map[ai.time.substring(0, 8)] = ai;
    } else {
      for (var j = 0; j < dest.length; j++) {
        var dj = dest[j];
        if (dj.initial.substring(0, 8) == ai.time.substring(0, 8)) {
          dj.busInfoList.push(ai);
          break;
        }
      }
    }
  }
  return dest;
}
// 邮箱验证
const fChkMail = (mail) => {
  var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
  return reg.test(mail);
}

// 手机号验证
const isValidNo = (mobileNo) => {
  var v = false;
  if (mobileNo == null || mobileNo == "" || mobileNo.length != 11) {
    return false;
  }
  var myreg = /^((1[0-9]{2})+\d{8})$/;
  if (myreg.test(mobileNo)) {
    v = true;
  }
  return v;
}

const investStatusFilter =(input)=>{
  let name = "";
  if (input != "" && input != null) {
    name = (input === "1") ? "未提交" : (input === "2") ? "已提交" : (input === "3") ? "资料预检通过" : (input === "4") ? "风控审核通过" : (input === "5") ? "已承接" : (input === "8") ? "已退案" : (input === "9") ? "已结案" : (input === "0") ? "已关闭" : (input === "A") ? "审核拒绝" : (input === "B") ? "待委托" : (input === "C") ? "已委托" : (input === "D") ? "风控审核中" : (input === "E") ? "合同未确认" : (input === "F") ? "合同已确认" : (input === "G") ? "合同已签约" : "其它";
  }
  return name;
}

const checkYearMonthDay = (input)=>{
  let strdate = "";
  if(input){
    let strDate = input.substring(0, 10);
    let arr = strDate.split('-');
    strdate = arr[0] + '年' + arr[1] + '月' + arr[2] + '日';
  }
  return strdate;

}

const getEntrustNameById = (input)=>{
  let str = '';
  switch (input) {
    case '1': str = '立案'; break;
    case '2': str = '开庭'; break;
    case '3': str = '办理财产保全手续'; break;
    case '4': str = '车辆信息'; break;
    case '5': str = '工商档案信息'; break;
    case '6': str = '婚姻档案信息'; break;
    case '7': str = '不动产档案信息'; break;
    case '8': str = '诉讼/执行档案信息'; break;
    case '9': str = '户籍信息'; break;
    case '10': str = '建设工程备案信息'; break;
    case '11': str = '实地查看涉案工程情况'; break;
    case '12': str = '实地查看被告经营情况'; break;
    default:
  }
  return str;
}

//时间格式化
const timetrans = (date, dayOrTime) => {
  if (!date) {
    return ''
  }
  var _date = new Date(date);//如果date为13位不需要乘1000
  var Y = _date.getFullYear() + '-';
  var M = (_date.getMonth() + 1 < 10 ? '0' + (_date.getMonth() + 1) : _date.getMonth() + 1) + '-';
  var D = (_date.getDate() < 10 ? '0' + (_date.getDate()) : _date.getDate()) + ' ';
  var h = (_date.getHours() < 10 ? '0' + _date.getHours() : _date.getHours()) + ':';
  var m = (_date.getMinutes() < 10 ? '0' + _date.getMinutes() : _date.getMinutes());
  var s = ':' + (_date.getSeconds() < 10 ? '0' + _date.getSeconds() : _date.getSeconds());
  if (dayOrTime === 'day') {
    return Y + M + D;
  } else if (dayOrTime === 'time') {
    return h + m + s;
  } else if (dayOrTime === 'timeHM') {
    return h + m;
  } else {
    return Y + M + D + h + m + s;
  }
}

const BankRateList = [
  { date: '2015-10-24', rate1: "4.35", rate2: "4.35", rate3: "4.75", rate4: "4.75", rate5: "4.90" },
  { date: '2015-08-26', rate1: "4.60", rate2: "4.60", rate3: "5.00", rate4: "5.00", rate5: "5.15" },
  { date: '2015-06-28', rate1: "4.85", rate2: "4.85", rate3: "5.25", rate4: "5.25", rate5: "5.40" },
  { date: '2015-05-11', rate1: "5.10", rate2: "5.10", rate3: "5.50", rate4: "5.50", rate5: "5.65" },
  { date: '2015-03-01', rate1: "5.35", rate2: "5.35", rate3: "5.75", rate4: "5.75", rate5: "5.90" },
  { date: '2014-11-22', rate1: "5.60", rate2: "5.60", rate3: "6.00", rate4: "6.00", rate5: "6.15" },
  { date: '2012-07-06', rate1: "5.60", rate2: "6.00", rate3: "6.15", rate4: "6.40", rate5: "6.55" },
  { date: '2012-06-08', rate1: "5.85", rate2: "6.31", rate3: "6.40", rate4: "6.65", rate5: "6.80" },
  { date: '2011-07-07', rate1: "6.10", rate2: "6.56", rate3: "6.65", rate4: "6.90", rate5: "7.05" },
  { date: '2011-04-06', rate1: "5.85", rate2: "6.31", rate3: "6.40", rate4: "6.65", rate5: "6.80" },
  { date: '2011-02-09', rate1: "5.60", rate2: "6.06", rate3: "6.10", rate4: "6.45", rate5: "6.60" },
  { date: '2010-12-26', rate1: "5.35", rate2: "5.81", rate3: "5.85", rate4: "6.22", rate5: "6.40" },
  { date: '2010-10-20', rate1: "5.10", rate2: "5.56", rate3: "5.60", rate4: "5.96", rate5: "6.14" },
  { date: '2008-12-23', rate1: "4.86", rate2: "5.31", rate3: "5.40", rate4: "5.76", rate5: "5.94" },
  { date: '2008-11-27', rate1: "5.04", rate2: "5.58", rate3: "5.67", rate4: "5.94", rate5: "6.12" },
  { date: '2008-10-30', rate1: "6.03", rate2: "6.66", rate3: "6.75", rate4: "7.02", rate5: "7.20" },
  { date: '2008-10-27', rate1: "6.12", rate2: "6.93", rate3: "7.02", rate4: "7.29", rate5: "7.47" },
  { date: '2008-10-09', rate1: "6.12", rate2: "6.93", rate3: "7.02", rate4: "7.29", rate5: "7.47" },
  { date: '2008-09-16', rate1: "6.21", rate2: "7.20", rate3: "7.29", rate4: "7.56", rate5: "7.74" },
  { date: '2007-12-21', rate1: "6.57", rate2: "7.47", rate3: "7.56", rate4: "7.74", rate5: "7.83" },
  { date: '2004-10-29', rate1: "5.22", rate2: "5.58", rate3: "5.76", rate4: "5.85", rate5: "6.12" },
  { date: '1990-01-01', rate1: "5.22", rate2: "5.58", rate3: "5.76", rate4: "5.85", rate5: "6.12" },
]

const _SYT_util = {
	/**
	 * 格式化金额
	 * 
	 * @param money
	 *            金额
	 * @param accuracy
	 *            精度(小数位数)
	 * @return 格式化后的金额
	 */

  isErrorAmount: function (input) {
    if (/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(input + '')) {
      return false;
    } else {
      return true;
    }
  },
  formatMoney: function (money, accuracy) {
    if (money == null || money == "") {
      return money;
    }
    money = money + "";
    var tempValue = money.replace(/\s/g, "");
    var tempArray = null;
    var v = "";
    // 如果为整数
    if (accuracy <= 0) {
      if (tempValue.indexOf(".") != -1) {
        v = tempValue.split(".")[0];
      } else {
        v = tempValue;
      }
    }
    // 如果为小数
    else {
      if (tempValue.indexOf(".") != -1) {
        tempArray = tempValue.split(".");
        v = tempArray[0]
          + "."
          + (tempArray[1] + "00000000000000000").substring(0,
            accuracy);
      } else {
        v = tempValue + "."
          + ("00000000000000000").substring(0, accuracy);
      }
    }
    return v;
  },

	/**
	 * 格式化日期
	 * 
	 * @param date
	 *            日期
	 * @param format
	 *            格式化样式,例如yyyy-MM-dd HH:mm:ss E
	 * @return 格式化后的金额
	 */
  formatDate: function (date, format) {
    var v = "";
    if (typeof date == "string" || typeof date != "object") {
      return;
    }
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    var hour = date.getHours();
    var minute = date.getMinutes();
    var second = date.getSeconds();
    var weekDay = date.getDay();
    var ms = date.getMilliseconds();
    var weekDayString = "";

    if (weekDay == 1) {
      weekDayString = "星期一";
    } else if (weekDay == 2) {
      weekDayString = "星期二";
    } else if (weekDay == 3) {
      weekDayString = "星期三";
    } else if (weekDay == 4) {
      weekDayString = "星期四";
    } else if (weekDay == 5) {
      weekDayString = "星期五";
    } else if (weekDay == 6) {
      weekDayString = "星期六";
    } else if (weekDay == 7) {
      weekDayString = "星期日";
    }

    v = format;
    // Year
    v = v.replace(/yyyy/g, year);
    v = v.replace(/YYYY/g, year);
    v = v.replace(/yy/g, (year + "").substring(2, 4));
    v = v.replace(/YY/g, (year + "").substring(2, 4));

    // Month
    var monthStr = ("0" + month);
    v = v.replace(/MM/g, monthStr.substring(monthStr.length - 2));

    // Day
    var dayStr = ("0" + day);
    v = v.replace(/dd/g, dayStr.substring(dayStr.length - 2));

    // hour
    var hourStr = ("0" + hour);
    v = v.replace(/HH/g, hourStr.substring(hourStr.length - 2));
    v = v.replace(/hh/g, hourStr.substring(hourStr.length - 2));

    // minute
    var minuteStr = ("0" + minute);
    v = v.replace(/mm/g, minuteStr.substring(minuteStr.length - 2));

    // Millisecond
    v = v.replace(/sss/g, ms);
    v = v.replace(/SSS/g, ms);

    // second
    var secondStr = ("0" + second);
    v = v.replace(/ss/g, secondStr.substring(secondStr.length - 2));
    v = v.replace(/SS/g, secondStr.substring(secondStr.length - 2));

    // weekDay
    v = v.replace(/E/g, weekDayString);
    return v;
  },

  formatDateTimeString: function (dateTimeString) {
    if (dateTimeString == null || dateTimeString == "") {
      return "";
    }
    dateTimeString = dateTimeString.replace(/ /g, "");
    dateTimeString = dateTimeString.replace(/\-/g, "");
    dateTimeString = dateTimeString.replace(/\:/g, "");
    var year = dateTimeString.substring(0, 4);
    var month = dateTimeString.substring(4, 6);
    var day = dateTimeString.substring(6, 8);
    var hour = dateTimeString.substring(8, 10);
    var minute = dateTimeString.substring(10, 12);
    var second = dateTimeString.substring(12, 14);

    var newString = "";
    if (year != "") {
      newString += year;
    }
    if (month != "") {
      newString += "-" + month;
    }
    if (day != "") {
      newString += "-" + day;
    }
    if (hour != "") {
      newString += " " + hour;
    }
    if (minute != "") {
      newString += ":" + minute;
    }
    if (second != "") {
      newString += ":" + second;
    }
    return newString;
  },

  formatDateToString: function () {
    var myDate = new Date();
    var month = myDate.getMonth() * 1 + 1;
    if (month < 10) {
      month = "0" + month;
    }
    var dateString = myDate.getFullYear() + "" + month + "" + myDate.getDate() + "" + myDate.getHours() + "" + "0000";
    return dateString;
  },

	/**
	 * 转化日期
	 * 
	 * @param dependedVal
	 *            string 日期 yyyy-MM-dd
	 * @return date
	 */
  datestrToDate: function (dependedVal) {
    var regEx = new RegExp("\\-", "gi");
    dependedVal = dependedVal.replace(regEx, "/");
    var milliseconds = Date.parse(dependedVal);
    var dependedDate = new Date();
    dependedDate.setTime(milliseconds);
    return dependedDate;
  },

	/**
	 * 比较两日期大小
	 * 
	 * @param dependedVal
	 * string 日期 yyyy-MM-dd
	 * startData
	 * endData   
	 * @return boolean
	 */
  compareDate: function (startData, endData) {
    var startTime = startData.replace(/-/g, "/");
    var endTime = endData.replace(/-/g, "/");
    var d1 = new Date(Date.parse(startTime));
    var d2 = new Date(Date.parse(endTime));
    if (d1 > d2) {
      return false;
    } else {
      return true;
    }
  },


  /**
 * 验证是手机号是否有效
 * @param mobileNo 充值手机号
 * @return boolean true 
 */
  // isValidNo: function (mobileNo) {
  //   var v = false;
  //   if (mobileNo == null || mobileNo == "" || mobileNo.length != 11) {
  //     return false;
  //   }
  //   //		var mobileHead = mobileNo.substr(0,3);
  //   //		var headArray = new Array(134,135,136,137,138,139,150,151,152,157,158,159,182,183,187,188,147,130,131,132,155,156,185,186,133,153,180,189,181);
  //   //        for(var i=0;i<headArray.length;i++){
  //   //           if(headArray[i] == mobileHead) {
  //   //              v = true;
  //   //              break;
  //   //           }
  //   //        }
  //   var myreg = /^((1[0-9]{2})+\d{8})$/;
  //   if (myreg.test(mobileNo)) {
  //     v = true;
  //   }
  //   return v;
  // },

	/* 
	用途：检查输入字符串是否只由汉字、字母组成 
	输入： 
	value：字符串 
	返回： 
	如果通过验证返回true,否则返回false 
	*/
  //判断姓名是否是汉字、字母组成 
  isChinaOrLett: function (s) {
    var flag;
    var regu = "^[a-zA-Z\u4e00-\u9fa5]+$";
    var re = new RegExp(regu);
    if (re.test(s)) {
      flag = true;
    } else {
      flag = false;
    }
    return flag;
  },

  //1.js验证只能输入6位数字.
  checkSixCode: function (value) {
    var flag = false;
    //定义正则表达式部分
    if (value == null || value == "" || value.length != 6) {
      return false;
    }
    if (/^[0-9]*$/.test(value * 1)) {
      flag = true;
    }
    return flag;
  },

  math: {
    // 加法精确计算(可传负数做减法计算)
    accAdd: function (arg1, arg2) {
      var r1, r2, m, c;
      try {
        r1 = arg1.toString().split(".")[1].length;
      } catch (e) {
        r1 = 0;
      }
      try {
        r2 = arg2.toString().split(".")[1].length;
      } catch (e) {
        r2 = 0;
      }

      c = Math.abs(r1 - r2);
      m = Math.pow(10, Math.max(r1, r2))
      if (c > 0) {
        var cm = Math.pow(10, c);
        if (r1 > r2) {
          arg1 = Number(arg1.toString().replace(".", ""));
          arg2 = Number(arg2.toString().replace(".", "")) * cm;
        } else {
          arg1 = Number(arg1.toString().replace(".", "")) * cm;
          arg2 = Number(arg2.toString().replace(".", ""));
        }
      } else {
        arg1 = Number(arg1.toString().replace(".", ""));
        arg2 = Number(arg2.toString().replace(".", ""));
      }
      return (arg1 + arg2) / m;

    },

    // 减精确计算
    accSub: function (arg1, arg2) {
      var r1, r2, m, c;
      try {
        r1 = arg1.toString().split(".")[1].length;
      } catch (e) {
        r1 = 0;
      }
      try {
        r2 = arg2.toString().split(".")[1].length;
      } catch (e) {
        r2 = 0;
      }

      c = Math.abs(r1 - r2);
      m = Math.pow(10, Math.max(r1, r2))
      if (c > 0) {
        var cm = Math.pow(10, c);
        if (r1 > r2) {
          arg1 = Number(arg1.toString().replace(".", ""));
          arg2 = Number(arg2.toString().replace(".", "")) * cm;
        } else {
          arg1 = Number(arg1.toString().replace(".", "")) * cm;
          arg2 = Number(arg2.toString().replace(".", ""));
        }
      } else {
        arg1 = Number(arg1.toString().replace(".", ""));
        arg2 = Number(arg2.toString().replace(".", ""));
      }
      return (arg1 - arg2) / m;

    },

    // 乘法精确计算
    accMul: function (arg1, arg2) {
      var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
      try {
        m += s1.split(".")[1].length;
      } catch (e) {
      }
      try {
        m += s2.split(".")[1].length;
      } catch (e) {
      }
      return Number(s1.replace(".", "")) * Number(s2.replace(".", ""))
        / Math.pow(10, m);

    },

    // 除法函数，用来得到精确的除法结果
    accDiv: function (arg1, arg2) {
      var t1 = 0, t2 = 0, r1, r2;
      try {
        t1 = arg1.toString().split(".")[1].length;
      } catch (e) {
      }
      try {
        t2 = arg2.toString().split(".")[1].length;
      } catch (e) {
      }
      r1 = Number(arg1.toString().replace(".", ""));
      r2 = Number(arg2.toString().replace(".", ""));
      return (r1 / r2) * Math.pow(10, t2 - t1);

    }
  },

  /**
  * 根据身份证还判断年龄性别以及年龄段（青年：40岁以下,中年：41-65岁,老年:66岁以上）
  * @param idNo 身份证号
  */
  analysisId: function (val) {
    if (val == "" || val == null || val == 'undefined') {
      return "";
    }
    var birthdayValue;
    var sexual;
    if (15 == val.length) { //15位身份证号码
      birthdayValue = val.charAt(6) + val.charAt(7);
      if (parseInt(birthdayValue) < 10) {
        birthdayValue = '20' + birthdayValue;
      } else {
        birthdayValue = '19' + birthdayValue;
      }
      birthdayValue = birthdayValue + '-' + val.charAt(8) + val.charAt(9) + '-' + val.charAt(10) + val.charAt(11);
      if (parseInt(val.charAt(14) / 2) * 2 != val.charAt(14)) {
        sexual = 'man';
      } else {
        sexual = 'woman';
      }
    }
    if (18 == val.length) { //18位身份证号码
      birthdayValue = val.charAt(6) + val.charAt(7) + val.charAt(8) + val.charAt(9) + '-' + val.charAt(10) + val.charAt(11) + '-' + val.charAt(12) + val.charAt(13);
      if (parseInt(val.charAt(16) / 2) * 2 != val.charAt(16)) {
        sexual = 'man';
      } else {
        sexual = 'woman';
      }
    }
    var ageGroup = this.ageGroups(birthdayValue);
    var returnData = {};
    returnData.sex = sexual;
    returnData.type = ageGroup;

    return returnData;
  },

  ageGroups: function (str) {
    //获取年龄
    var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
    var age, ageGroup;
    if (r == null) {
      return false;
    }
    var d = new Date(r[1], r[3] - 1, r[4]);
    if (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4]) {
      var Y = new Date().getFullYear();
      age = Y - r[1];
    }
    //年龄段
    if (age <= 40) {
      ageGroup = 'young';
    } else if (age >= 66) {
      ageGroup = 'old';
    } else {
      ageGroup = 'middleAge';
    }
    return ageGroup;
  },

  getRad: function (d) {
    return d * Math.PI / 180.0;
  },

  /**
   * 经纬度距离计算
   * caculate the great circle distance
   * @param {Object} lat1
   * @param {Object} lng1
   * @param {Object} lat2
   * @param {Object} lng2
   */
  getGreatCircleDistance: function (lat1, lng1, lat2, lng2) {
    var EARTH_RADIUS = 6378137;    //单位米

    var radLat1 = this.getRad(lat1);
    var radLat2 = this.getRad(lat2);

    var a = radLat1 - radLat2;
    var b = this.getRad(lng1) - this.getRad(lng2);

    var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
    s = s * EARTH_RADIUS;
    s = Math.round(s * 10000) / 10000.0;

    return s;
  }
  , getTodayStr: function () {
    var _date = new Date();//如果date为13位不需要乘1000
    var Y = _date.getFullYear();
    var M = _date.getMonth() + 1 < 10 ? '0' + (_date.getMonth() + 1) : _date.getMonth() + 1;
    var D = _date.getDate() < 10 ? '0' + (_date.getDate()) : _date.getDate();
    var h = _date.getHours() < 10 ? '0' + _date.getHours() : _date.getHours();
    var m = _date.getMinutes() < 10 ? '0' + _date.getMinutes() : _date.getMinutes();
    var s = _date.getSeconds() < 10 ? '0' + _date.getSeconds() : _date.getSeconds();
    return {
      date: Y + '' + M + '' + D,
      time: h + '' + m + '' + s
    }
  },
  
}
const _YHC_util = {
  //身份证号合法性验证
  //支持15位和18位身份证号
  //支持地址编码、出生日期、校验位验证
  IdentityCodeValid: function (card) {
    //是否为空  
    if (card === '') {
      return false;
    }
    //校验长度，类型  
    if (this.isCardNo(card) === false) {
      return false;
    }
    //检查省份  
    if (this.checkProvince(card) === false) {
      return false;
    }
    //校验生日  
    if (this.checkBirthday(card) === false) {
      return false;
    }
    //检验位的检测  
    if (this.checkParity(card) === false) {
      return false;
    }
    return true;
  },


  //检查号码是否符合规范，包括长度，类型  
  isCardNo: function (card) {
    //身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X  
    var reg = /(^\d{15}$)|(^\d{17}(\d|X)$)/;
    if (reg.test(card) === false) {
      return false;
    }

    return true;
  },


  //Luhm校验规则：16位银行卡号（19位通用）:
  // 1.将未带校验位的 15（或18）位卡号从右依次编号 1 到 15（18），位于奇数位号上的数字乘以 2。
  // 2.将奇位乘积的个十位全部相加，再加上所有偶数位上的数字。
  // 3.将加法和加上校验位能被 10 整除。
  //bankno为银行卡号 banknoInfo为显示提示信息的DIV或其他控件
  luhmCheck: function (bankno) {
    var lastNum = bankno.substr(bankno.length - 1, 1);//取出最后一位（与luhm进行比较）

    var first15Num = bankno.substr(0, bankno.length - 1);//前15或18位
    var newArr = new Array();
    for (var i = first15Num.length - 1; i > -1; i--) {    //前15或18位倒序存进数组
      newArr.push(first15Num.substr(i, 1));
    }
    var arrJiShu = new Array();  //奇数位*2的积 <9
    var arrJiShu2 = new Array(); //奇数位*2的积 >9

    var arrOuShu = new Array();  //偶数位数组
    for (var j = 0; j < newArr.length; j++) {
      if ((j + 1) % 2 == 1) {//奇数位
        if (parseInt(newArr[j]) * 2 < 9)
          arrJiShu.push(parseInt(newArr[j]) * 2);
        else
          arrJiShu2.push(parseInt(newArr[j]) * 2);
      }
      else //偶数位
        arrOuShu.push(newArr[j]);
    }

    var jishu_child1 = new Array();//奇数位*2 >9 的分割之后的数组个位数
    var jishu_child2 = new Array();//奇数位*2 >9 的分割之后的数组十位数
    for (var h = 0; h < arrJiShu2.length; h++) {
      jishu_child1.push(parseInt(arrJiShu2[h]) % 10);
      jishu_child2.push(parseInt(arrJiShu2[h]) / 10);
    }

    var sumJiShu = 0; //奇数位*2 < 9 的数组之和
    var sumOuShu = 0; //偶数位数组之和
    var sumJiShuChild1 = 0; //奇数位*2 >9 的分割之后的数组个位数之和
    var sumJiShuChild2 = 0; //奇数位*2 >9 的分割之后的数组十位数之和
    var sumTotal = 0;
    for (var m = 0; m < arrJiShu.length; m++) {
      sumJiShu = sumJiShu + parseInt(arrJiShu[m]);
    }

    for (var n = 0; n < arrOuShu.length; n++) {
      sumOuShu = sumOuShu + parseInt(arrOuShu[n]);
    }

    for (var p = 0; p < jishu_child1.length; p++) {
      sumJiShuChild1 = sumJiShuChild1 + parseInt(jishu_child1[p]);
      sumJiShuChild2 = sumJiShuChild2 + parseInt(jishu_child2[p]);
    }
    //计算总和
    sumTotal = parseInt(sumJiShu) + parseInt(sumOuShu) + parseInt(sumJiShuChild1) + parseInt(sumJiShuChild2);

    //计算Luhm值
    var k = parseInt(sumTotal) % 10 == 0 ? 10 : parseInt(sumTotal) % 10;
    var luhm = 10 - k;

    if (lastNum == luhm && lastNum.length != 0) {
      return true;
    } else {
      return false;
    }
  },


  //取身份证前两位,校验省份  
  checkProvince: function (card) {
    var province = card.substr(0, 2);
    if (vcity[province] == undefined) {
      return false;
    }
    return true;
  },

  //检查生日是否正确  
  checkBirthday: function (card) {
    var len = card.length;
    //身份证15位时，次序为省（3位）市（3位）年（2位）月（2位）日（2位）校验位（3位），皆为数字  
    if (len == '15') {
      var re_fifteen = /^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/;
      var arr_data = card.match(re_fifteen);
      var year = arr_data[2];
      var month = arr_data[3];
      var day = arr_data[4];
      var birthday = new Date('19' + year + '/' + month + '/' + day);
      return this.verifyBirthday('19' + year, month, day, birthday);
    }
    //身份证18位时，次序为省（3位）市（3位）年（4位）月（2位）日（2位）校验位（4位），校验位末尾可能为X  
    if (len == '18') {
      var re_eighteen = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/;
      var arr_data = card.match(re_eighteen);
      var year = arr_data[2];
      var month = arr_data[3];
      var day = arr_data[4];
      var birthday = new Date(year + '/' + month + '/' + day);
      return this.verifyBirthday(year, month, day, birthday);
    }
    return false;
  },

  //校验日期  
  verifyBirthday: function (year, month, day, birthday) {
    var now = new Date();
    var now_year = now.getFullYear();
    //年月日是否合理  
    if (birthday.getFullYear() == year && (birthday.getMonth() + 1) == month && birthday.getDate() == day) {
      //判断年份的范围（3岁到100岁之间)  
      var time = now_year - year;
      if (time >= 3 && time <= 100) {
        return true;
      }
      return false;
    }
    return false;
  },

  //校验位的检测  
  checkParity: function (card) {
    //15位转18位  
    card = this.changeFivteenToEighteen(card);
    var len = card.length;
    if (len == '18') {
      var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
      var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
      var cardTemp = 0, i, valnum;
      for (i = 0; i < 17; i++) {
        cardTemp += card.substr(i, 1) * arrInt[i];
      }
      valnum = arrCh[cardTemp % 11];
      if (valnum == card.substr(17, 1)) {
        return true;
      }
      return false;
    }
    return false;
  },

  //15位转18位身份证号  
  changeFivteenToEighteen: function (card) {
    if (card.length == '15') {
      var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
      var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
      var cardTemp = 0, i;
      card = card.substr(0, 6) + '19' + card.substr(6, card.length - 6);
      for (i = 0; i < 17; i++) {
        cardTemp += card.substr(i, 1) * arrInt[i];
      }
      card += arrCh[cardTemp % 11];
      return card;
    }
    return card;
  },

  //将字符串变成数组
  strToArr: function (str) {
    var tempData = new Array();
    if (str.length > 0) {
      for (var i = 0; i < str.length; i++) {
        tempData.push(str[i]);
      }
    }
    var tempLength = 6 - tempData.length;
    for (var i = 0; i < tempLength; i++) {
      tempData.push("");
    }
    return tempData;
  },

  //hasClass
  hasClass: function (elem, cls) {
    cls = cls || '';
    if (cls.replace(/\s/g, '').length == 0) return false;
    return new RegExp(' ' + cls + ' ').test(' ' + elem.className + ' ');
  },

  //addClass
  addClass: function (elem, cls) {
    if (!this.hasClass(elem, cls)) {
      elem.className += ' ' + cls;
    }
  },

  //removeClass
  removeClass: function (elem, cls) {
    if (this.hasClass(elem, cls)) {
      var newClass = ' ' + elem.className.replace(/[\t\r\n]/g, '') + ' ';
      while (newClass.indexOf(' ' + cls + ' ') >= 0) {
        newClass = newClass.replace(' ' + cls + ' ', ' ');
      }
      elem.className = newClass.replace(/^\s+|\s+$/g, '');
    }
  },

  /*验证营业执照是否合法：营业执照长度须为15位数字，前14位为顺序码，
  *最后一位为根据GB/T 17710 1999(ISO 7064:1993)的混合系统校验位生成算法
  *计算得出。此方法即是根据此算法来验证最后一位校验位是否政正确。如果
  *最后一位校验位不正确，则认为此营业执照号不正确(不符合编码规则)。*/
  isValidBusCode: function (busCode) {
    return true;
    //            var ret=false;
    //            if(busCode.length==15){
    //                var sum=0;
    //                var s=[];
    //                var p=[];
    //                var a=[];
    //                var m=10;
    //                p[0]=m;
    //                for(var i=0;i<busCode.length;i++){
    //                   a[i]=parseInt(busCode.substring(i,i+1),m);
    //                   s[i]=(p[i]%(m+1))+a[i];
    //                   if(0==s[i]%m){
    //                     p[i+1]=10*2;
    //                   }else{
    //                     p[i+1]=(s[i]%m)*2;
    //                    }    
    //                }                                       
    //                if(1==(s[14]%m)){
    //                   //营业执照编号正确!
    //                    ret=true;
    //                }else{
    //                   //营业执照编号错误!
    //                    ret=false;
    //                 }
    //            }//如果营业执照为空
    //            else if(""==busCode){
    //                ret=false;
    //            }else{
    //                ret=false;
    //            }
    //            return ret;
  },

  /**
  *验证组织机构代码是否合法：组织机构代码为8位数字或者拉丁字母+“-”+1位校验码。
  *验证最后那位校验码是否与根据公式计算的结果相符。
  *编码规则请参看
  *http://wenku.baidu.com/view/d615800216fc700abb68fc35.html
  */
  isValidOrgCode: function (orgCode) {
    //return ""==orgCode || orgCode.length==10;
    //return true;
    var ret = false;
    var codeVal = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
    var intVal = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35];
    var crcs = [3, 7, 9, 10, 5, 8, 4, 2];
    if (!("" == orgCode) && orgCode.length == 10) {
      var sum = 0;
      for (var i = 0; i < 8; i++) {
        var codeI = orgCode.substring(i, i + 1);
        var valI = -1;
        for (var j = 0; j < codeVal.length; j++) {
          if (codeI == codeVal[j]) {
            valI = intVal[j];
            break;
          }
        }
        sum += valI * crcs[i];
      }
      var crc = 11 - (sum % 11);

      switch (crc) {
        case 10: {
          crc = "X";
          break;
        } default: {
          break;
        }
      }
      //最后位验证码正确
      if (crc == orgCode.substring(9)) {
        ret = true;
      } else {
        ret = false;
      }
    } else if ("" == orgCode) {
      ret = false;
    } else {
      ret = false;
    }
    return ret;
  },

  //邮箱验证
  fChkMail: function (mail) {
    var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
    return reg.test(mail);
  },
  isLawyerNo: function (lawyerNo) {
    if (lawyerNo) {
      var reg = /^[1|A]\d{14,16}$/;
      return reg.test(String(lawyerNo));
    } else {
      return false
    }
  }
}
const filterCaseTypeId=function (input) {
  var caseType = "";
  if (input != "" && input != null) {
    
    var caseTypeList = JSON.parse(wx.getStorageSync('caseTypeListCache'));
    for (var i = 0; i < caseTypeList.length; i++) {
      if (caseTypeList[i].caseTypeId == input) {
        caseType = caseTypeList[i].caseTypeName;
        break;
      }
    }
  }
  return caseType;
}

module.exports = {
  formatTime: formatTime,
  formatDate: formatDate,
  sortByTime: sortByTime,
  fChkMail: fChkMail,
  isValidNo: isValidNo,
  timetrans: timetrans,
  filterFormatAmt: filterFormatAmt,
  investStatusFilter: investStatusFilter,
  BankRateList: BankRateList,
  _SYT_util: _SYT_util,
  _YHC_util:_YHC_util,
  filterCaseTypeId: filterCaseTypeId,
  getEntrustNameById: getEntrustNameById,
  checkYearMonthDay:checkYearMonthDay
}
